Repository navigation
Add PhysioNet2019Dataset for hourly ICU sepsis time series - #1790
Conversation
Test CoverageTotal: 89.32% (65464 / 73288 lines)
|
|
/review Generated by Claude Code |
| continue | ||
| dest = root_path / match.group(1) | ||
| if not dest.exists(): | ||
| tasks.append((base + rel, dest)) |
There was a problem hiding this comment.
[low] SHA256SUMS hashes are downloaded but never verified
download_physionet2019 reads the SHA256SUMS.txt manifest only to list file names. The per-file digests it contains are never compared with the downloaded files, so a corrupted or truncated .psv would be used silently and later skipped by the dest.exists() check. Consider verifying each file's SHA-256 against the manifest after download, as pyhealth/models/generators/synthea.py does for its jar. If verification is not added, the docstring should say it does not check integrity.
| logger.info("Downloading %d PhysioNet 2019 files into %s", len(tasks), root_path) | ||
| with concurrent.futures.ThreadPoolExecutor(max_workers=max_workers) as pool: | ||
| futures = [pool.submit(_run_fetch, url, dest) for url, dest in tasks] | ||
| for fut in concurrent.futures.as_completed(futures): |
There was a problem hiding this comment.
[low] A failed download waits for every queued file before raising
The loop calls fut.result() on the first failure, but the surrounding ThreadPoolExecutor with block then waits for all remaining queued futures. A network outage early in the run would therefore keep fetching or retrying up to ~40k files before the error surfaces. Cancel the pending futures (for example, call pool.shutdown(cancel_futures=True) or cancel each future) when one fails.
| selected_sets = _normalize_sets(sets) | ||
| if download: | ||
| download_physionet2019(root_path, sets=selected_sets) | ||
| if not all( |
There was a problem hiding this comment.
[low] Cached CSV tables silently ignore a changed sets argument
If the three CSVs already exist, sets is ignored: PhysioNet2019Dataset(root, sets=('B',)) returns patients from both hospitals if the tables were built earlier. The limitation is documented only in the class docstring. Consider adding a line to the rst page, or logging a warning when the requested sets differ from the built ones. PhysioNet2012Dataset behaves the same way, so this need not block the merge.
| ] | ||
| assert hourly_labels == [(1, 0), (2, 0), (3, 1)] | ||
|
|
||
| def test_negative_patient_and_iculos_starting_gt_1(self, tmp_path: Path) -> None: |
There was a problem hiding this comment.
[low] Test name does not match what the test checks
test_negative_patient_and_iculos_starting_gt_1 uses no negative patient ID. It checks that a stay starting at ICULOS 4 and a negative HospAdmTime are parsed. Rename it to something like test_stay_starting_after_hour_one_keeps_hour_numbers.
There was a problem hiding this comment.
AI Review
suggestion: approve
decision: approve
Thank you for contributing PhysioNet2019Dataset. It adds the open-access PhysioNet/CinC 2019 ICU sepsis data, with separate events, labels and patients tables, a manifest-driven download and a streaming table builder. This looks ready to merge.
The change is self-contained. It subclasses BaseDataset without modifying it, and the only shared code it uses is the existing download_file utility, which it doesn't change. Adding the export to __init__.py is registration. The dataset cites its source and paper in the docstring and docs, and the docs match the code.
Coverage is above the bar. physionet2019.py is at 89.09%, against the 80% guideline for each file. The whole repository is at 89.32%, against the 60% bar.
Optional suggestions:
SHA256SUMS.txtis fetched but the hashes are never checked. You could verify each downloaded file against it.- If one download fails, the executor still waits for all the queued downloads before the error is raised. Cancelling the pending futures on the first failure would surface it sooner.
- If
setsis changed after the CSVs are built, the cached CSVs are reused silently. This is only noted in the class docstring. A log warning, or a note in the docs page, would help. test_negative_patient_and_iculos_starting_gt_1doesn't test a negative patient. Renaming it would make its purpose clearer.- The default HTTP path with retries, and the
setsvalidation, have no tests.
Reviewed commit d101cd1
Part of #1789
Summary
Adds
PhysioNet2019Datasetfor the open-access PhysioNet/Computing in Cardiology Challenge 2019 ICU sepsis dataset (Reyna et al., Critical Care Medicine 2020), filling the PhysioNet 2019 dataset gap noted in #1605 / BTY-49.Key Design Decisions
events,labels,patients):events: non-NaN hourly vital-sign and laboratory observations only (hour,parameter,value), keepingSepsisLabelstrictly isolated from input features.labels: one row per patient-hour (hour,sepsis_label), preserving hours where all 34 dynamic variables areNaN(e.g., hour 1 ofp000001.psv).patients: one row per ICU stay holdinghospital("A"or"B"), static admission descriptors,num_hours,sepsis, andfirst_sepsis_hour.NaNat the dataset layer: Laboratory tests average 94.8% hourly missingness with strong informative missingness (MNAR). No forced forward-fill or imputation is applied during ingestion so downstream tasks can configure missingness handling per model family.parse_wide_hourly_recordaccepts configurable column roles/delimiters, andprepare_physionet2019streams.psvstays directly into atomic.tmpCSVs rather than buffering >10M rows in memory.download_physionet2019parses the officialSHA256SUMS.txtmanifest, skips existing files, and supports an injectablefetcherfor offline unit testing.File Guide
pyhealth/datasets/physionet2019.py: Dataset class, variable group constants (VITAL_VARIABLES,LAB_VARIABLES,DYNAMIC_VARIABLES,STATIC_VARIABLES),download_physionet2019,parse_wide_hourly_record, andprepare_physionet2019.pyhealth/datasets/configs/physionet2019.yaml: Three-table dataset configuration.pyhealth/datasets/__init__.py: ExportPhysioNet2019Dataset.tests/core/test_physionet2019.py: 10 fast offline unit tests using synthetic.psvstays intmp_path.docs/api/datasets/pyhealth.datasets.PhysioNet2019Dataset.rst&docs/api/datasets.rst: Sphinx API reference and dataset index entries.Testing & Verification
pytest tests/core/test_physionet2019.py -v: 10 passed (offline synthetic fixtures).python tools/check_pr_rules.py --base upstream/master --head HEAD: All PR contribution rules passed..psvstays (training_setA+training_setB): builtpatients.csv(40,336 rows, 1.5 MB),labels.csv(1,552,210 rows, 50.0 MB), andevents.csv(10,486,913 rows, 419.2 MB) in 17.3s.Disclosure
AI coding assistance was used during implementation and test drafting; all design decisions, code paths, and test assertions were reviewed and verified manually.